import api from "../../api/api.js"
import routerUtil from "../../router/routerUtil.js"
const sys = defineStore(
"sys",
{
    state: ()=>({
        added: false, // 加载路由标志
        menuList: null, // 顶部菜单
		activeMenu:null,
		userInfo:{
			nickName:"昵称",
			headUrl:"头像",
			loginName:"登陆名",
			phone:"13716343106",
			roleNames:"",
			permissionList:[],
			roleList:[]
		},
		tagsShowViewList:[]
    }),
	actions: {
		generateRoutes() {
			return new Promise(resolve => {
				
				api.sysMenuFindUserMenuByTree().then(result => {
					let menuList = result
					//配置路由
					const otherRoutes = []
					routerUtil.initRouterNode(otherRoutes, menuList)
					
					//添加所有菜单
					this.menuList = menuList
					
					resolve(otherRoutes)
				})
			})
		},
		updateUserInfo(userInfo) {
			if(userInfo.roleNameList){
				userInfo.roleNames = userInfo.roleNameList.join(",")
			}else{
				userInfo.roleNames = ''
			}
			this.userInfo = userInfo
		},
		updateMenulist(menuList) {
		    this.menuList = menuList;
		},
	}
});

export default sys;
